import {useSceneStore} from '@/stores/scene'
class motionControl{
    cacheMap= new Map();
    sceneStore=useSceneStore();
    constructor(listData){
    }
    start(data){
        console.log(this.sceneStore.animationRefList)
        this.sceneStore.animationRefList.forEach(function(element){
            element.props.timelineData.actions.forEach((action,idx) => {
                if(data.action.id == action.id){
                    // element.setShowAnimation(true)
                    element.playAnimation(idx)
                }
            });
           
        })
    }
    update(data){
        this.sceneStore.animationRefList.forEach(function(element){
            element.props.timelineData.actions.forEach((action,idx) => {
                if(data.action.id == action.id){
                    if(data.time>=action.start&&data.time<=action.end){
                        element.setShowAnimation(true)
                        element.setAnimationByTime(data.time,idx)
                    }else{
                        element.setShowAnimation(false)
                    }
                }
            });
            
        })
    }
    stop(data){
        this.sceneStore.animationRefList.forEach(function(element){
            element.props.timelineData.actions.forEach(action => {
                if(data.action.id == action.id){
                    element.stopAnimation()
                }
            });
            
        })
        
    }
    enter(data){
        this.sceneStore.animationRefList.forEach(function(element){
            element.props.timelineData.actions.forEach(action => {
                if(data.action.id == action.id){
                    element.setShowAnimation(true)
                }
            });
            
        })
        
    }
    leave(data){
        this.sceneStore.animationRefList.forEach(function(element){
            element.props.timelineData.actions.forEach(action => {
                if(data.action.id == action.id){
                    element.setShowAnimation(false)
                }
            });
            
        })
        
    }
}

export default motionControl;